import { request} from "../../request/index"
import {getSetting,chooseAddress,openSetting,showModal,showToast} from "../../utils/asyncWx.js"
// pages/cart/index.js
Page({
  data: {
    address:{},
    cart:[],
    totalNum:0,
    totalPrice:0
  },
  onShow(){
    // 1获取缓存中的收获地址
    const address=wx.getStorageSync("address");
    // 获取缓存中的购物车数据
    let cart=wx.getStorageSync("cart")||[];
    // 过滤后的购物车数组
    cart=cart.filter(v=>v.checked);
    this.setData({address});

     // 总价格  总数量
     let totalNum=0;
     let totalPrice=0;
     cart.forEach(v=>{
         totalPrice+=v.num*v.goods_price;
         totalNum+=v.num
     })
 
     this.setData({
       cart, 
       totalNum,
       totalPrice,
       address
     });
  },
//  点击 支付
handleOrderPay(){
    // 1判断缓存中有没有token
    const token=wx.getStorageSync('token')
    // 2判断
    if(!token){
        wx.navigateTo({
          url: '/pages/auth/index',
        })
        return
    }
    console.log("已经存在token")
}
})